import 'package:fate_blind_box/theme/theme_color.dart';
import 'package:fate_blind_box/utils/assets.dart';
import 'package:fate_blind_box/utils/provider.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../../../network/Api.dart';
import '../../../network/http_config.dart';
import '../../../utils/loading.dart';
import '../../../utils/snack_bar.dart';
//编辑企业简介
class recommendCodeUI extends StatefulWidget {

  recommendCodeUI({Key? key}) : super(key: key);

  @override
  State<recommendCodeUI> createState() => _recommendCodeUIState();
}

class _recommendCodeUIState extends State<recommendCodeUI> {

  final TextEditingController _nameController = TextEditingController();
  String _inviteCode = "";
  String _profileNo = "";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  // 修改个人简介
  _getUserinfo() async {

    final res = await Api.getInstance().ModifyMeIntroduce(Provider.memberId,_nameController.text);
    final data = res['msg'];
    ThemeSnackBar.show(context, data);
    Navigator.of(context).pop();
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    return Scaffold(
        appBar: AppBar(

          iconTheme: const IconThemeData(
            color: Colors.white,
          ),
          title: const Text('推荐码',style: TextStyle(color: Colors.white,fontSize: 16),),
          elevation: 0,
          backgroundColor: Colors.black,

          actions: <Widget>[

            Container(
              margin: const EdgeInsets.only(right: 0,top: 5,bottom: 10),
              height: 31,
              child: TextButton(
                style: TextButton.styleFrom(
                  backgroundColor: Colors.black,
                  shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
                  textStyle: const TextStyle(color: Colors.white),
                ),

                child: Icon(Icons.more_horiz_outlined,color: Colors.white,),
                // const Text('完成',style: TextStyle(color: Colors.white),),

                onPressed: () {

                },
              ),
            )


          ],
        ),
        backgroundColor: Colors.black,
        body: Align(
          alignment: Alignment.center,
          child: Container(
            width: size.width,
            height: 375,
            color: Colors.white,
            child: Center(
              child: QrImageView(
                padding: const EdgeInsets.all(3),
                backgroundColor: Colors.white,
                data: _getQrInfo(),
                version: QrVersions.auto,
                size: 334,
              ),
            ),
          ),
        ),
    );
  }

  String _getQrInfo() {
    print('xxxx   ${HttpConfig.baseUrl}?invite_code=$_inviteCode');
    return _inviteCode.isEmpty ? "" : HttpConfig.baseUrl + "?invite_code=$_inviteCode";
  }

  _getQr() {
    loading(() async {
      final res = await Api.getInstance().getMemberInfo(Provider.memberId);
      if (res?['data']?['shareCode']?.toString()?.isNotEmpty == true) {
        setState(() {
          _inviteCode = res['data']['shareCode'];
          _profileNo = res['data']['profileNo'];
          print(_inviteCode);
        });
      } else {
        toast("获取邀请码失败！");
      }
    });
  }
}